package logic

import (
	"baidu/models/mysql"
	"context"

	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PopularAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPopularAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PopularAddLogic {
	return &PopularAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加热门帖子
func (l *PopularAddLogic) PopularAdd(in *baidurpc.PopularAddRequest) (*baidurpc.PopularAddResponse, error) {
	// todo: add your logic here and delete this line

	popular := mysql.Popular{
		HeadImage: in.HeadImage,
		Context:   in.Context,
		GiveNum:   int(in.GiveNum),
	}

	mysql.DB.Debug().Create(&popular)

	return &baidurpc.PopularAddResponse{
		Id: int64(popular.ID),
	}, nil
}
